home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 25 / Cream of the Crop 25.iso / os2 / srefv12i.zip / status.cmd < prev    next >
OS/2 REXX Batch file  |  1997-02-28  |  9KB  |  253 lines

  1. /* This is the STATUS demo of SRE-FILTER's server side proceessing
  2.  
  3. Use STATUS.HTM to invoke this routine.
  4. */
  5.  
  6. status:
  7. parse arg  ddir, tempfile, reqstrg,list,verb ,uri,user, ,
  8.           basedir ,workdir,privset,enmadd,transaction,verbose, ,
  9.          servername,host_nickname,homedir
  10.  
  11. if verb=" " then do
  12.    say "This SRE-Filter procedure is not meant to be run in standalone mode "
  13.    exit
  14. end  /* Do */
  15.  
  16. list=translate(list, ' ', '+'||'090a0d'x)  /* Whitespace, etc. */
  17.  
  18.  
  19. /* special request: initialize dircache */
  20. if pos('INIT_DIRCACHE=1',upper(list)) then do
  21.   if wordpos('SUPERUSER',upper(privset))=0 then do
  22.       'header add WWW-Authenticate: Basic Realm=<!DIR Cache>'  /* challenge */
  23.        return sref_response('unauth', "You do not have !DIR cache deletion rights ",tempfile,servername)
  24.   end  /* Do */
  25.  
  26.  
  27.   call init_dircache
  28.  'FILE ERASE TYPE text/html NAME' tempfile
  29.  return 'Done with STATUS (initialize !dir cache)'
  30.  
  31. end  /* Do */
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38. /* Information will be returned in a temporary file, whose name
  39. is provided in the tempfile variable.
  40. Note that it's a good idea to start your HTML documents with a dtd doctype statement
  41.  */
  42.         call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 2.0//EN">'
  43.  
  44.         call lineout tempfile, "<html><head><title>Results from STATUS request</title>"
  45.         call lineout tempfile, "</head><body>"
  46.         call lineout tempfile,' <h2>Results from  Status Request </h2>'
  47.  
  48.         call lineout tempfile,' <h3>The arguments recieved by STATUS </h3> '
  49.  
  50.         call lineout tempfile,' <dl> '
  51.  
  52.         call lineout tempfile,' <dt>  DDIR = <code>' ddir '</code> '
  53.         call lineout tempfile,' <dd>  The "data directory" (where your HTML documents should be) '
  54.         call lineout tempfile,' <dt>  TEMPFILE = <code>' tempfile ' </code> '
  55.         call lineout tempfile,' <dd> The "temporary file" (used to build this response)'
  56.  
  57.         call lineout tempfile,' <dt>  ACTION = <code>' reqstrg ' </code> '
  58.         call lineout tempfile,' <dd>  The  <b>action</b> portion of the request selector'
  59.  
  60.  
  61.         call lineout tempfile,' <dt>  LIST = <code>' list ' </code> '
  62.         call lineout tempfile,' <dd> The <b>parameters</b>: '
  63.         call lineout tempfile, '<br> ... if POST method, from the "body" of the request '
  64.         call lineout tempfile,' <br> ... if GET method ,  from after the "?" in the request selector.  '
  65.  
  66.         call lineout tempfile,' <dt>  VERB = <code>' VERB ' </code> '
  67.         call lineout tempfile,' <dd>  The HTTP method '
  68.  
  69.         call lineout tempfile,' <dt>  URI = <code>' URI ' </code> '
  70.         call lineout tempfile,' <dd> The full <b>request string</b> '
  71.  
  72.         call lineout tempfile,' <dt> USER = <code>' user ' </code> '
  73.         call lineout tempfile,' <dd> USERS ip addrees '
  74.  
  75.         call lineout tempfile,' <dt>  BASEDIR = <code>' basedir ' </code> '
  76.         call lineout tempfile,' <dd> The "working directory" (where SRE-FILTER and GoServe live) '
  77.  
  78.         call lineout tempfile,' <dt>  WORKDIR = <code>' workdir ' </code> '
  79.         call lineout tempfile,' <dd>  Temporary working files area (for <em>user-supplied </em> programs ) '
  80.  
  81.         call lineout tempfile,' <Dt> Your privileges are: '
  82.         call lineout tempfile,' <DD> <code> ' privset ' </code> '
  83.  
  84.         call lineout tempfile,' <Dt> The host nickname '
  85.         call lineout tempfile,' <DD> <code> ' host_nickname ' </code> '
  86.  
  87.         call lineout tempfile, '<dt> The ~ (home directory) string '
  88.         call lineout tempfile,' <Dd> <code> ' homedir  ' </code>'
  89.  
  90.          call lineout tempfile,'</dl>'
  91.  
  92.  
  93. /* Read the "header" -- and display the results */
  94.        'READ HEADER VAR FOO '
  95.          call lineout tempfile,' <h3> The Request Header </h3> '
  96.  
  97.         call lineout tempfile,' <dd> <blockquote> <pre>' foo  '</pre> </blockquote>'
  98.  
  99.         call lineout tempfile,' <h3> Some User & Server Info </h3> '
  100.  
  101.  
  102. /* This section demonstrates the use of some GOSERVE functions */
  103.    cname=clientname()
  104.    caddr=extract('CLIENTADDR')
  105.    ssoft=server()
  106.    sname=servername
  107.    saddr=extract('SERVERADDR')
  108.    sport=extract('SERVERPORT')
  109.  
  110.    call lineout tempfile,' <ul> '
  111.    call lineout tempfile,' <li> Client ip address:  <code>' caddr '</code>'
  112.    call lineout tempfile,' <li> Client name:  <code>' cname '</code>'
  113.    call lineout tempfile,' <li> Server ip address: <code>' saddr '</code>'
  114.    call lineout tempfile,' <li> Server port:  <code>' sport '</code>'
  115.  
  116.    call lineout tempfile,' <li> Server name:  <code>' sname '</code>'
  117.    call lineout tempfile, ' <li> Server software:  <code>' ssoft '</code>'
  118.   aver=sref_version()
  119.    call lineout tempfile,' <li>  Filter version: <code> ' aver ' </code>'
  120.    call lineout tempfile,' <li> Your privileges are: <tt> ' privset ' </tt>'
  121.    call lineout tempfile,' </ul> '
  122.  
  123. /* superusers and inhouse users get to see sre-filter's parameters,
  124. if desired (by pressing a link to configure */
  125.  
  126.   if wordpos('SUPERUSER',privset)=0 then signal getuse
  127.   call lineout tempfile,' <h3> SRE-FILTER settings </h3> '
  128.   call lineout tempfile,' <br>   Do you want to see the  <A href='
  129.   call lineout tempfile,' "/config2?todo=show">current settings of SRE-FILTER'"'s parameters</A>? <br>"
  130.  
  131.  
  132. getuse: nop
  133. /* get some "intensity of use " statistics */
  134.  reptime=extract('RESPONSETIME')
  135.  numtrans=extract('TRANSACTIONS')
  136.  whenstart=extract('LASTSTART')
  137.  nclients=extract('CLIENTS')
  138.  
  139.    call lineout tempfile,' <h3> Use Statistics </h3> '
  140.    call lineout tempfile,' GoServe started: ' whenstart
  141.  
  142.    call lineout tempfile,'<BR> # of transactions ' numtrans  ', avg. reponsetime = 'reptime ' sec. '
  143.  
  144.    call lineout tempfile,'<BR> Current # of clients = ' nclients
  145.  
  146.  
  147. /* review cache etnries */
  148. foo=strip(get_value('tempdata_dir'),'t','\')
  149. call lineout tempfile,'<h3> Cache status (in ' foo ') </h3> '
  150. dshs=foo||'\_*.DSH'
  151. oo=sysfiletree(dshs,fred,'FO')
  152. call lineout tempfile,' # of files in the <EM>!DIR cache </EM>= ' fred.0
  153. aport=extract('serverport')
  154. cshs=foo||'\_*.'||aport
  155. oo=sysfiletree(cshs,fred,'FO')
  156. call lineout tempfile,'<br> # of files in the <EM>SSI-Cache files </EM> = ' fred.0 '<br>'
  157.  
  158.  
  159. /* Use the HOST function -- demonstrates the use of external calls */
  160.  
  161. /* but first "parse" the parameter list, and store in a simple stem variable */
  162.   m=0
  163.   do until list=""
  164.     parse var list opt1 '&' list
  165.     m=m+1
  166.     parse var opt1 optname.m '=' optvalue.m
  167.   end
  168.   optname.0=m
  169.  
  170. /* see if one of the opts is "getip" */
  171.    chkip=0 ;
  172.    do mm=1 to optname.0
  173.       if translate(optname.mm)='GETIP' then do
  174.          chkip=optvalue.mm
  175.          leave
  176.       end
  177.   end
  178.  
  179. /* if we found a GETIP, and got it's value, then lookit up */
  180.   if chkip<>0 & chkip<>"" then do
  181. /* Note use of the address cmd xxx to call a OS/2 level command  */
  182.     A=RXQUEUE('S','SESSION')    /* SINCE QUEUE MIGHT BE A THREAD'S QUEUE */
  183.     do queued(); pull .; end                   /* flush */
  184.     address cmd '@host' chkip '| rxqueue'     /* execute the command */
  185.     parse pull hostresult                      /* get result */
  186.  
  187.     call lineout tempfile,' <h3> Look up address </h3> '
  188.  
  189.     call lineout tempfile,' <pre> ' hostresult ' </pre>'
  190.   end
  191.  
  192.  
  193.  
  194.  
  195. /* all done, write final end-of-html elements */
  196.   call lineout tempfile,'<body> </html>'
  197.   call lineout tempfile
  198.  
  199.      'FILE ERASE TYPE text/html NAME' tempfile
  200.   return 'Done with STATUS'
  201.  
  202. /* ----------- */
  203. /* get environment value. Typically, look for host-specific
  204. value first, and then look for generic value (if no host given,
  205. skip host-specific lookup )
  206. vname: variable to lookup
  207. hname0: Special instructions:
  208.   hname0=0 -- do not look under host nickname
  209.   hname0=1 -- do not look under default
  210.  */
  211. /* ------------ */
  212. get_value: procedure expose enmadd host_nickname
  213. parse upper arg vname,hname0
  214. if hname0=0 then
  215.         hname=' '
  216. else
  217.     hname=strip(host_nickname)
  218.  
  219. vname=strip(vname) ;
  220. if hname<>' ' then do
  221.    booger=strip(enmadd||vname||'.'||hname)
  222.    aval=value(booger,,'os2environment')
  223.    if aval<>' ' | hname0=1 Then
  224.         return aval
  225. end
  226. aval=value(enmadd||vname,,'os2environment')
  227. return aval
  228.  
  229.  
  230. /* *********** */
  231. /* initialize dir cache */
  232. init_dircache:
  233.   call lineout tempfile, '<!doctype html public "-//IETF//DTD HTML 2.0//EN">'
  234.   call lineout tempfile, "<html><head><title>Initialize !DIR Cache</title>"
  235.   call lineout tempfile, "</head><body>"
  236.   call lineout tempfile,' <h2>Initialize !DIR Cache</h2>'
  237.   foo=strip(get_value('tempdata_dir'),'t','\')
  238.   dshs=foo||'\_*.DSH'
  239.   oo=sysfiletree(dshs,fred,'FO')
  240.   do mm=1 to fred.0
  241.      foo2=sysfiledelete(fred.mm)
  242.   end /* do */
  243.   iid=foo||'\_DIRLIST.IDX'
  244.   foo=sysfiledelete(iid)
  245.   call lineout tempfile,  ' # of files <b>deleted</b> from the <EM>!DIR cache </EM> = ' fred.0
  246. /* all done, write final end-of-html elements */
  247.   call lineout tempfile,'<body> </html>'
  248.   call lineout tempfile
  249.  
  250.   'FILE ERASE TYPE text/html NAME' tempfile
  251.   return 0
  252.  
  253.